#ifndef SYNTAXHIGHLIGHTER_H
#define SYNTAXHIGHLIGHTER_H

#include <QSyntaxHighlighter>
#include <QTextCharFormat>
#include <QRegularExpression>
#include <QHash>
#include <QTextEdit>
#include <QPair>
#include <vector>

class SyntaxHighlighter : public QSyntaxHighlighter
{
    Q_OBJECT

public:
    SyntaxHighlighter(QTextDocument* parent = nullptr);
    std::vector <std::pair<std::pair<int, int>, QString> > errorInfo;
    bool showErrorHighLight = 0;

public slots:
    //void setHighlightLine(int lineNumber);
    //void setSearchText(const QString &text);//添加接口来设置查找文本
    void setDebugInfo(const std::vector <std::pair<std::pair<int, int>, QString> > &info);//添加接口来设置调试信息
    //初始化高亮规则
    void setupRule();
    void setupRuleDark();

protected:
    void highlightBlock(const QString& text) override ;

private:
    struct Rule {
         QRegularExpression pattern;
         QTextCharFormat format;
     };
     QVector<Rule> rules;

     //用于匹配标点符号的格式和正则表达式
     QTextCharFormat punctuationFormat;
     QRegularExpression punctuationPattern;

     //用于匹配预处理的格式和正则表达式
     QTextCharFormat preprocessorFormat;
     QRegularExpression preprocessorPattern;

     //用于匹配括号的格式和正则表达式
     QTextCharFormat braceFormat;
     QRegularExpression bracePattern;

     //用于存储关键字及其格式的哈希表
     QHash<QString, QTextCharFormat> keywordFormat;

     //用于匹配数字的格式和正则表达式
     QTextCharFormat numberFormat;
     QRegularExpression numberPattern;

     //用于匹配双引号的格式和正则表达式
     QTextCharFormat stringFormat;
     QRegularExpression stringPattern;

     //用于匹配单行注释的格式和正则表达式
     QTextCharFormat commentFormat;
     QRegularExpression commentPattern;

     //用于高亮行的格式
     QTextCharFormat highlightFormat;
     int highlightLineNumber = -1;

     //用于匹配查找的格式和正则表达式
     QTextCharFormat searchFormat;
     QRegularExpression searchPattern;
     QString searchText;

     //调试信息相关
     QTextCharFormat debugFormat;



 };


#endif // SYNTAXHIGHLIGHTER_H
